package com.dao.c.backend.service.impl;

import com.dao.c.backend.common.CommonResult;
import com.dao.c.backend.common.MessageCode;
import com.dao.c.backend.common.StatusCode;
import com.dao.c.backend.dao.CategoryMapper;
import com.dao.c.backend.entity.Category;
import com.dao.c.backend.entity.Model;
import com.dao.c.backend.dao.ModelMapper;
import com.dao.c.backend.service.IModelService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 张幸晔
 * @since 2025-02-22
 */
@Service
public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements IModelService {

    @Autowired
    ModelMapper modelMapper;
    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public CommonResult modelListMid(Model model) {
        LambdaQueryWrapper<Model> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Model::getStatus, StatusCode.DATA_EXIST).eq(Model::getId, model.getId())
                .select(Model.class, i -> !i.getColumn().equals("url") && !i.getColumn().equals("api") && !i.getColumn().equals("status"));
        Model dbModel = modelMapper.selectOne(lambdaQueryWrapper);
        if (dbModel == null) {
            return new CommonResult<>(StatusCode.ERROR, MessageCode.SELECTFAIL, null);
        }
        return new CommonResult<>(StatusCode.SUCCESS, MessageCode.SELECT, dbModel);
    }


}
